//
//  ViewController.swift
//  1.5.Adding Buttons to the User Interface with UIButton
//
//  Created by joker on 15/7/21.
//  Copyright (c) 2015年 joker. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    var button: UIButton!
    
    func buttonIsPressed(sender: UIButton) {
        println("Button is pressed")
    }
    
    func buttonIsTapped(sender: UIButton){
        println("Button is tapped.")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        button = UIButton.buttonWithType(.System) as? UIButton
        
        button.frame = CGRect(x: 110, y: 70, width: 100, height: 44)
        
        button.setTitle("Press Me", forState: .Normal)
        button.setTitle("I'm Pressed", forState: .Highlighted)
        
        button.addTarget(self, action: "buttonIsPressed:", forControlEvents: .TouchDown)
        button.addTarget(self, action: "buttonIsTapped:", forControlEvents: .TouchUpInside)
        
        button.setBackgroundImage(UIImage(named: "Normal"), forState: .Normal)
        button.setBackgroundImage(UIImage(named: "Highlighted"), forState: .Highlighted)
        
        button.center = view.center
        view.addSubview(button)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

